<template>
 <TreeSelect ret-attr="value" :multiple="multiple" v-model="selectVal" :treeData="treeData" :placeholder='placeholder' strategy="SHOW_ALL"></TreeSelect>
</template>

<script>
import AppFrame from '../libs/app-frame';
import TreeSelect from '../components/tree-select';
export default {
    name: 'partners-dict-select',
    props: ['partnersId' ,'label','value','multiple','placeholder','parentId'],
     model: {
        prop: 'value',
        event: 'updateVal'
    },
    components:{
        TreeSelect
    },
    data: function() {	
        return {
            selectVal:'',
            treeData:[]
        }
    },
    created () {
      this.getData(this.partnersId,this.label,this.parentId);
    },

    watch: {
        partnersId:async function(curVal,oldVal){
         if(curVal!=oldVal){
                 await this.getData(curVal ,this.label, this.parentId);
            }
        },

        label:async function(curVal,oldVal){
            if(curVal!=oldVal){
                 await this.getData(this.partnersId,curVal , this.parentId);
            }
        },

        parentId:async function(curVal,oldVal){
            if(curVal!=oldVal){
                 await this.getData(this.partnersId,this.label , curVal);
            }
        },

        value:function(curVal,oldVal){
            if(curVal!=oldVal){
                 this.selectVal=curVal;
            }
           
        },
        selectVal:function(curVal,oldVal){
         
            if(curVal!=oldVal){
                 this.setValue(curVal);
            }
            this.setValue(curVal);
        }
         
    },
    methods: {
        init:function(){
            if(this.placeholder || this.placeholder==='') this.placeholder="请选择"; 
        },
        getData:async function(partnersId , label,parentId){
            let postData={
                partnersId:partnersId,
                label:this.label,
                parentId:this.parentId
            }
        console.log(postData);
          let ret = await AppFrame.Http.Post("/manage-api/system/partners-dict/getdictsTreeData",postData);
         if(ret && ret.Result==1){
              this.treeData=ret.Data;
          }
        },
         setValue: function(val) {
            this.$emit("updateVal", val);
        },
    }
}
</script>

<style scoped>

</style>